package com.inspection.controller.sys;

import com.inspection.entity.SysRoleDO;
import com.inspection.model.dto.SysRoleDTO;
import com.inspection.model.dto.SysRoleQueryDTO;
import com.inspection.service.SysRoleService;
import com.inspection.support.Wrapper;
import com.inspection.support.anno.SysLogAnno;
import com.inspection.support.model.ItemList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhaoqi
 * @since 2020-12-08
 */
@RestController
public class SysRoleController {

    @Autowired
    private SysRoleService sysRoleService;


    @RequestMapping("/sys/role/page")
    public Wrapper<Page<SysRoleDO>> pageRole(@RequestBody SysRoleQueryDTO page) {
        return Wrapper.ok(sysRoleService.pageSysRole(page));
    }

    @RequestMapping("/sys/role/list")
    public Wrapper<ItemList<SysRoleDO>> queryRole(@RequestBody SysRoleQueryDTO page) {
        return Wrapper.ok(ItemList.buildItems(sysRoleService.querySysRole(page)));
    }

    @RequestMapping("/sys/role/get")
    public Wrapper<SysRoleDO> getRole(@RequestBody SysRoleQueryDTO query) {
        return Wrapper.ok(sysRoleService.getSysRole(query));
    }

    @SysLogAnno(operateCode =100401,operateName = "系统角色：新增")
    @RequestMapping("/sys/role/save")
    public Wrapper<String> saveRole(@RequestBody SysRoleDTO save) {
        sysRoleService.saveSysRole(save);
        return Wrapper.ok("ok");
    }

    @SysLogAnno(operateCode =100402,operateName = "系统角色：更新")
    @RequestMapping("/sys/role/update")
    public Wrapper<String> updateRole(@RequestBody SysRoleDTO update) {
        sysRoleService.updateSysRole(update);
        return Wrapper.ok("ok");
    }

    @SysLogAnno(operateCode =100403,operateName = "系统角色：删除")
    @RequestMapping("/sys/role/del")
    public Wrapper<String> delRole(@RequestBody SysRoleDTO del) {
        sysRoleService.delSysRole(del);
        return Wrapper.ok("ok");
    }

    @SysLogAnno(operateCode =100404,operateName = "系统角色：批量删除")
    @RequestMapping("/sys/role/batchDel")
    public Wrapper<String> batchDelRole(@RequestBody SysRoleDTO del) {
        sysRoleService.batchDelSysRole(del);
        return Wrapper.ok("ok");
    }



}
